package com.px.device.controller;

import com.px.common.annotation.Log;
import com.px.common.core.controller.BaseController;
import com.px.common.core.domain.AjaxResult;
import com.px.common.core.page.TableDataInfo;
import com.px.common.enums.BusinessType;
import com.px.common.utils.poi.ExcelUtil;
import com.px.device.domain.AirportInfo;
import com.px.device.domain.AirportVo;
import com.px.device.service.IAirportInfoService;
import com.px.framework.aes.AesSecurityParameter;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 机场信息Controller
 * 
 * @author WRJ
 * @date 2024-08
 */
@Api("飞行行动管理")
@RestController
@RequestMapping("/device/airport")
public class AirportInfoController extends BaseController
{
    @Autowired
    private IAirportInfoService airportInfoService;

    /**
     * 查询机场信息列表
     */
    @ApiOperation("查询机场信息列表")
    @PreAuthorize("@ss.hasPermi('device:airport:query')")
    @GetMapping("/list")
    @AesSecurityParameter(outEncode = true)
    public TableDataInfo list(AirportInfo airportInfo){
        airportInfo.setDelFlag("0");
        startPage();
        List<AirportInfo> list = airportInfoService.selectAirportInfoList(airportInfo);
        return getDataTable(list);
    }

    /**
     * 查询机场信息列表,包含环境温度等OSD信息
     */
    @ApiOperation("查询机场信息列表,包含环境温度等OSD信息")
    @PreAuthorize("@ss.hasPermi('device:airport:query')")
    @GetMapping("/volist")
    @AesSecurityParameter(outEncode = true)
    public TableDataInfo volist(AirportInfo airportInfo)
    {
        airportInfo.setDelFlag("0");
        airportInfo.setAirportModel("3-1-0");
        startPage();
        List<AirportVo> list = airportInfoService.selectAirportVoList(airportInfo);
        return getDataTable(list);
    }

    /**
     * 导出机场信息列表
     */
    @ApiOperation("导出机场信息列表")
    @PreAuthorize("@ss.hasPermi('device:airport:query')")
    @Log(title = "机场信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @AesSecurityParameter
    public void export(HttpServletResponse response, AirportInfo airportInfo)
    {
        List<AirportInfo> list = airportInfoService.selectAirportInfoList(airportInfo);
        ExcelUtil<AirportInfo> util = new ExcelUtil<AirportInfo>(AirportInfo.class);
        util.exportExcel(response, list, "机场信息数据");
    }

    /**
     * 获取机场信息详细信息
     */
    @ApiOperation("获取机场信息详细信息")
    @PreAuthorize("@ss.hasPermi('device:airport:query')")
    @GetMapping(value = "/{airportId}")
    @AesSecurityParameter(outEncode = true)
    public AjaxResult getInfo(@PathVariable("airportId") Long airportId)
    {
        return success(airportInfoService.selectAirportVoByAirportId(airportId));
    }


    /**
     * 新增机场信息
     */
    @ApiOperation("新增机场信息")
    @PreAuthorize("@ss.hasPermi('device:airport:edit')")
    @Log(title = "机场信息", businessType = BusinessType.INSERT)
    @PostMapping
    @AesSecurityParameter(outEncode = true)
    public AjaxResult add(@RequestBody AirportInfo airportInfo)
    {
        return toAjax(airportInfoService.insertAirportInfo(airportInfo));
    }

    /**
     * 修改机场信息
     */
    @ApiOperation("修改机场信息")
    @PreAuthorize("@ss.hasPermi('device:airport:edit')")
    @Log(title = "机场信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @AesSecurityParameter(outEncode = true)
    public AjaxResult edit(@RequestBody AirportInfo airportInfo)
    {
        return toAjax(airportInfoService.updateAirportInfo(airportInfo));
    }

    /**
     * 删除机场信息
     */
    @ApiOperation("删除机场信息")
    @PreAuthorize("@ss.hasPermi('device:airport:remove')")
    @Log(title = "机场信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{airportIds}")
    @AesSecurityParameter(outEncode = true)
    public AjaxResult remove(@PathVariable Long[] airportIds)
    {
        return toAjax(airportInfoService.deleteAirportInfoByAirportIds(airportIds));
    }
}
